const http = require('http');
const app = http.createServer();
const template = require('art-template');
const path = require('path');
const dateformat = require('dateformat')
template.defaults.imports.dateformat = dateformat
app.on('request',(req,res)=>{
    if(req.url == '/' || req.url == '/index'){
        var html = template(path.join(__dirname,'./views/index.art'),{})
        res.end(html)
    }else if(req.url == '/list'){
        var html = template(path.join(__dirname,'./views/list.art'),{posts:[
            {title:'第一篇文章的标题',time:1573653555098},
            {title:'第二篇文章的标题',time:1573653555098},
            {title:'第三篇文章的标题',time:1573653555098},
            {title:'第四篇文章的标题',time:1573653555098}
        ]})
        res.end(html)
    }else{
        res.end('404 not found')
    }
})
app.listen(3000,()=>{
    console.log('服务器开启成功，正在监听端口3000')
})

